package com.zhoushihao.class0815;

import java.util.*;

public class AssignSeats {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Map<String, Integer>> number = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String[] s = sc.nextLine().split(" ");
            Map<String, Integer> studentInfo = new HashMap<>();
            studentInfo.put(s[1], Integer.parseInt(s[0]));
            number.add(studentInfo);
        }
        Map<String, String> seats = new LinkedHashMap<>();
        for (int i = 0; i < number.size(); i++) {
            for (Map.Entry<String, Integer> entry : number.get(i).entrySet()) {
                int flag = 0;
                if (entry.getValue() == 1) {
                    for (int j = number.size() - 1; j > 0; j--) {
                        for (Map.Entry<String, Integer> entry_2 : number.get(j).entrySet()) {
                            if (entry_2.getValue() == 0) {
                                seats.put(entry.getKey(), entry_2.getKey());
                                number.remove(j);
                                flag = 1;
                                break;
                            }
                        }
                        if (flag == 1) {
                            break;
                        }
                    }
                } else {
                    for (int j = number.size() - 1; j > 0; j--) {
                        for (Map.Entry<String, Integer> entry_2 : number.get(j).entrySet()) {
                            if (entry_2.getValue() == 1) {
                                seats.put(entry.getKey(), entry_2.getKey());
                                number.remove(j);
                                flag = 1;
                                break;
                            }
                        }
                        if (flag == 1) {
                            break;
                        }
                    }
                }
            }
        }
        for (Map.Entry<String, String> entry : seats.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}
